package Review;

import com.sun.scenario.effect.Merge;

public class Text3 {
    public static void main(String[] args) {
        MyLinkedList list = new MyLinkedList();
        list.addFirst(21);
        list.addFirst(21);
        list.addFirst(3);
        list.addFirst(4);
        list.addFirst(5);
        list.display();
        list.addIndex(2,21);
        list.display();
        System.out.println("===============");
        list.removeKeyAll(21);
        list.display();
    }
    public static void main4(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addLast(11);
        mySingleList.addLast(21);
        mySingleList.addLast(31);
        mySingleList.addLast(41);
        mySingleList.createLoop();
        boolean flg = mySingleList.hasCycle(mySingleList.head);
        System.out.println(flg);
        //
        MySingleList.ListNode ret = mySingleList.detectCycle(mySingleList.head);
        System.out.println(ret.val);
    }
    public static MySingleList.ListNode Merge(MySingleList.ListNode head1,
                                       MySingleList.ListNode head2) {
        MySingleList.ListNode newHead = new MySingleList.ListNode(0);
        MySingleList.ListNode tmp = newHead;
        while (head1 != null && head2 != null) {
            if (head1.val < head2.val) {
                tmp.next = head1;
                head1 = head1.next;
                tmp = tmp.next;
            }else {
                tmp.next = head2;
                head2 = head2.next;
                tmp = tmp.next;
            }

        }
        if (head1 != null) tmp.next = head1;
        if (head2 != null) tmp.next = head2;
        return newHead.next;
    }


    public static void main3(String[] args) {
        MySingleList list1 = new MySingleList();
        list1.addLast(21);
        list1.addLast(23);
        list1.addLast(33);
        list1.addLast(55);

        MySingleList list2 = new MySingleList();
        list2.addLast(20);
        list2.addLast(25);
        list2.addLast(61);
        list2.addLast(199);

        MySingleList.ListNode ret = Merge(list1.head,list2.head);
        list1.display(ret);
    }
    public static void main2(String[] args) {
        MySingleList list = new MySingleList();
        list.createLink();
        MySingleList.ListNode ret = list.ReverseList();
        list.display(ret);
    }
    public static void main1(String[] args) {
        MySingleList list = new MySingleList();
        list.createLink();
        //list.diaplay();
        System.out.println("=============");
        boolean ret = list.contains(5);
        System.out.println(ret);
        System.out.println(list.size());
        System.out.println("====测试头插=====");
        list.addFirst(11);
        list.addFirst(55);
        list.addFirst(66);
        list.display();
        System.out.println("====测试尾插======");
        list.addLast(22);
        list.addLast(33);
        list.display();
        /*System.out.println("=====测试指定下标插入节点=====");
        list.addIndex(2,666);
        list.addIndex(2,666666);
        list.addIndex(0,555);
        list.addIndex(list.size(),3333);
        list.diaplay();*/
        /*System.out.println("=====测试指定下标插入节点=====");
        list.addIndex(0,111);
        list.diaplay();*/
        //list.addIndex(11,999);
        //list.addIndex(-1,9999);
        System.out.println("====测试删除指定的key======");
        list.remove(66);
        list.remove(11);
        list.remove(33);
        list.display();
        list.addFirst(11);
        list.addFirst(11);
        list.addFirst(11);
        list.display();
        list.removeAllKey(11);
        list.display();
    }
}
